package com.crowdfunding.listener;

import com.crowdfunding.bean.Member;
import com.crowdfunding.service.MemberService;
import com.crowdfunding.service.TicketService;
import com.crowdfunding.util.ApplicationContextUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.springframework.context.ApplicationContext;

/**
 * 实名认证审批失败需要执行的操作
 */
public class RefuseListener implements ExecutionListener {
    @Override
    public void notify(DelegateExecution delegateExecution) throws Exception {
        Integer memberid = (Integer)delegateExecution.getVariable("memberid");
        //更新member表的authstatus的字段 0-实名认证失败
        //ApplicationContext ioc= new ClassPathXmlApplicationContext("");//不能自己创建ioc容器，保证容器是唯一的
        //ApplicationContext ioc=WebApplicationContextUtils.getWebApplicationContext(application);//需要获取application对象，可以使用流程变量或者ThreadLocal
        //获取IOC容器，通过自定义的工具类，实现Spring接口，以接口注入的方式获取IOC容器对象
        ApplicationContext ioc= ApplicationContextUtils.applicationContext;
        MemberService memberService=ioc.getBean(MemberService.class);
        Member member = memberService.getMemberById(memberid);
        member.setAuthstatus("0");
        memberService.updateAuthstatus(member);
        //更新ticket表的status字段 0->1表示流程结束
        TicketService ticketService=ioc.getBean(TicketService.class);
        ticketService.updateStatusByMemberId(memberid);
    }
}
